//
//
//  @ Project : AgriMarketSystem
//  @ Date : 18/10/2013
//  @ Author : NTT
//
//
using System.Collections.Generic;
using System.Linq;
namespace AgriMarketService
{
    public class Unit
    {
        private int unitId;

        public int UnitId
        {
            get { return unitId; }
            set { unitId = value; }
        }
        private string unitName;

        public string UnitName
        {
            get { return unitName; }
            set { unitName = value; }
        }
        public Unit()
        { 
        }
        public Unit(int unitId, string unitName)
        {
            this.unitId = unitId;
            this.unitName = unitName;
        }

        public static List<Unit> GetAllUnits()
        { 
            AgriMarketDataClassesDataContext db=new AgriMarketDataClassesDataContext();
            return (from unit in db.Tbl_Units
                    select new Unit() { UnitId = unit.UnitId, UnitName = unit.UnitName }).ToList();
        }
        public static Unit GetUnitById(int unitId)
        {
            AgriMarketDataClassesDataContext db = new AgriMarketDataClassesDataContext();
            return (from unit in db.Tbl_Units
                    where unit.UnitId==unitId
                    select new Unit() { UnitId = unit.UnitId, UnitName = unit.UnitName }).FirstOrDefault();
        }
    }
}